<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态组件</title>
</head>

<body>
    <div id="app">
        <button @click="change('step2')">第二步</button>
        <button @click="change('step1')">第一步</button>
        <button @click="change('step3')">第三步</button>
        <keep-alive>
            <component :is="name"></component>
        </keep-alive>
    </div>

</body>

<script src="../day06/lib/vue.js"></script>
<script>
    var step1 = { template: '<div>这是第一步的操作</div>' }
    var step2 = { template: '<div>这是第二步的操作</div>' }
    var step3 = { template: '<div>这是第三步的操作</div>' }

    var vm = new Vue({
        el: "#app",
        data: {
            name: "step2",
        },
        components: {
            step1,
            step2,
            step3
        },
        methods: {
            change: function (name) {
                this.name = name
            }
        }
    })
</script>

</html>